<?php
namespace App\Libs\Base;
class Constant
{
    const MOBILE_REGREX = '/^1\d{10}$/';
    const EMAIL_REGREX = '/^[0-9a-zA-Z]+([_a-z0-9\-\.]+)*@[a-zA-Z0-9]{2,}(?:[-.][a-zA-Z0-9]+)*\.[a-zA-Z]{2,}$/';
    const NICK_REGREX = '/^[\x{4e00}-\x{9fa5}a-zA-Z0-9\_]+$/u';
    const URL_REGREX = '#^http://([\w-]+\.)+[\w-]+(/[\w-./?%&=]*)?$#';
    const PASSWORD_REGREX = '/^[\x21-\x7e]+$/';
    const NUMERIC_REGREX = '/\d/';
    const LOWERCASE_CHAR_REGREX = '/[a-z]/';
    const UPPERCASE_CHAR_REGREX = '/[A-Z]/';
    const SPECIAL_CHAR_REGREX = '/(?=[\x21-\x7e]+)[^A-Za-z0-9]/';
    const CHINESE_NAME = '/^[\x{4e00}-\x{9fa5}]{2,}$/u';

    // OK, ERR
    const OK = 0;
    const ERR = 1;

    const INVALID_CAPTCHA = 2;

	const INVALID_SIGN = 3;

	const REDIRECT_REGIST = 99;

    const UNLOGIN = 10001;//未登录
    const USER_UNACTIVE = 10002;
    const USER_FORBIDEN = 10003;
	const USER_NOT_FOUND = 10004;
	const PASSWORD_ERROR = 10005;
	const WX_FRIST_LOGIN = 10006;//微信第一次注册 统一值
    const MAIL_SEND_FAILED = 11000;

    const DENY = 10403;
    const AUDIT_DENY = 10400;

	const RESOURCE_MISSING = 90001;
    const UNKNOWN = 99999;

    // Error code definition
    




    public static function message($code, $args = array()) {
        $msg = isset(self::$messages[$code]) ? self::$messages[$code] : self::$messages[self::UNKNOWN];
        if (is_array($args))
        foreach ($args as $key => $arg) {
            $msg = str_replace('{' . $key . '}', $arg, $msg);
        }
        return $msg;
    }


    protected static $messages = array(
        self::OK => 'ok',
        self::ERR => 'failed',
        self::INVALID_CAPTCHA => '验证码无效',
		self::INVALID_SIGN => '无效请求',
        self::UNLOGIN => '未登录',
        self::UNKNOWN => '未知错误',
		self::RESOURCE_MISSING => '资源不足',       
		self::REDIRECT_REGIST => '重定向注册',
    );
}


